package com.liucxu.qiushimeinv.Presenter.Impl;

import com.liucxu.qiushimeinv.Model.Bean.BaseBean;
import com.liucxu.qiushimeinv.Model.Bean.LoginResponseBean;
import com.liucxu.qiushimeinv.Model.ILoginModel;
import com.liucxu.qiushimeinv.Model.Impl.LoginModelImpl;
import com.liucxu.qiushimeinv.Presenter.ILoginPresenter;
import com.liucxu.qiushimeinv.Utils.CommonSubscriber;
import com.liucxu.qiushimeinv.Utils.TransformUtils;
import com.liucxu.qiushimeinv.View.IView.ILoginView;

/**
 * 登陆Presenter接口实现类
 * Created by liukanshan on 2017/1/1.
 */

public class LoginPresenterImpl implements ILoginPresenter {

    private ILoginView loginView;
    private ILoginModel loginModel;

    public LoginPresenterImpl(ILoginView iLoginView) {

        if (iLoginView != null) {
            loginView = iLoginView;
        }
        loginModel = new LoginModelImpl();
    }

    @Override
    public void login(String user_name, String password) {
        loginView.showLoading();
        loginModel.login(user_name, password).compose(TransformUtils.<LoginResponseBean>defaultScheduler()).subscribe(new CommonSubscriber<LoginResponseBean>() {
            @Override
            public void onSuccess(LoginResponseBean response) {
                loginView.hideLoading();
                loginView.setUserView(response);
            }

            @Override
            public void onFailure(BaseBean response) {
                loginView.hideLoading();
                loginView.showError(response);
            }
        });
    }
}
